const gulp = require('gulp')
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
const path = require('path')
const clean = require('gulp-clean')
const script = done => {
    // 1\. 找到文件
    gulp.src(path.join(__dirname, './index.js'))
        .pipe(babel({
            presets: ['@babel/env']
        }))
        // 2\. 压缩文件
        .pipe(uglify({
            mangle: true,//类型：Boolean 默认：true 是否修改变量名
            compress: true,//类型：Boolean 默认：true 是否完全压缩
        }))
        // 3\. 另存压缩后的文件
        .pipe(gulp.dest('dist/'))
        done()
}

const copy =  done => {
    gulp.src([path.join(__dirname, 'package.json'), path.join(__dirname, 'README.md')])
      .pipe(gulp.dest('dist/'))
      done()
  }
 const clear = done=> {
     gulp.src('dist/', {read: false,allowEmpty: true})
        .pipe(clean());
        done()
}
exports.default = gulp.series(clear, script, copy)